//
//  PreviousForgetViewController.m
//  viewController
//
//  Created by rimi on 15/10/10.
//  Copyright (c) 2015年 ouyang. All rights reserved.
//

#import "PreviousForgetViewController.h"
#import "AnimationView.h"

#define THEMECOLORLINE [UIColor colorWithWhite:0.728 alpha:1.000]

@interface PreviousForgetViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) UITextField *passwordTF;
@property (nonatomic, strong) UITextField *repeatPasswordTF;
@property (nonatomic, strong) UITextField *phoneNumberTF;
@property (nonatomic, strong) UITextField *codeTF;
@property (nonatomic, strong) UIView *upview;
@property (nonatomic, strong) UIView *textView;
@property (nonatomic, strong) UIButton *completeButton;
@property (nonatomic, strong) AnimationView *animationView;
@property (nonatomic, strong) UIView *downView;

@end

@implementation PreviousForgetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initUserInterface];
    //    [self animation];
}
- (void)initUserInterface {
    [self initBackButton];
    [self initNavTitle:@"忘记密码"];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.downView];
    [self.downView addSubview:self.animationView];
    [self.animationView addSubview:self.textView];
    //    [self.textView addSubview:self.usernameTF];
    [self.textView addSubview:self.passwordTF];
    [self.textView addSubview:self.repeatPasswordTF];
    [self.textView addSubview:self.phoneNumberTF];
    [self.textView addSubview:self.codeTF];
    [self.view addSubview:self.completeButton];
    
    UIView *baseView = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(160, 70, 120, 40), NO)];
    baseView.backgroundColor = [UIColor colorWithWhite:0.600 alpha:1.000];
    baseView.layer.cornerRadius = 5;
    UIView *upView = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(160, 70, 120, 40), NO)];
    upView.backgroundColor = THEMECOLOR;
    upView.layer.cornerRadius = 5;
    UILabel *label = [[UILabel alloc] initWithFrame:flexibleFrame(CGRectMake(160, 70, 120, 40), NO)];
    self.upview = upView;
    //手势
    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [upView addGestureRecognizer:singleTap];
    singleTap.delegate = self;
    
    singleTap.cancelsTouchesInView = NO;
    label.text = @"获取验证码";
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    
    [self.textView addSubview:baseView];
    [self.textView addSubview:upView];
    [self.textView addSubview:label];
    
    UIView *pinsView = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 16, 16), NO)];
    pinsView.center =  flexibleCenter(CGPointMake(375 / 2, 64));
    pinsView.backgroundColor = [UIColor colorWithRed:0.518 green:0.529 blue:0.511 alpha:1.000];
    pinsView.layer.cornerRadius = 8;
    pinsView.layer.shadowColor = [UIColor blackColor].CGColor;//阴影颜色
    pinsView.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
    pinsView.layer.shadowOpacity = 0.5;//不透明度
    pinsView.layer.shadowRadius = 5.0;
    [self.view addSubview:pinsView];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)handleSingleTap:(UITapGestureRecognizer *)sender {
    //    if (self.phoneNumberTF.text.length == 0) {
    //        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请输入您的手机号" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    //        [alertView show];
    //        return;
    //    }else if (![self validateMobile:self.phoneNumberTF.text]) {
    //        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请输入正确格式的手机号" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    //        [alertView show];
    //        return;
    //    }
    self.upview.frame = flexibleFrame(CGRectMake(160, 70, 0, 40), NO);
    [UIView animateWithDuration:10 animations:^{
        self.upview.frame = flexibleFrame(CGRectMake(160, 70, 120, 40), NO);
    }];
}
- (CAKeyframeAnimation *)KeyrotationAnimation {
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
    animation.values = @[@(-M_PI / 36), @(M_PI / 40), @(-M_PI / 50), @(M_PI / 70), @0];
    animation.duration = 2;
    animation.keyTimes = @[@0, @0.25, @0.5, @0.75, @1];
    animation.additive = YES;
    return animation;
}
- (UITextField *)passwordTF {
    if (!_passwordTF) {
        _passwordTF = ({
            UITextField *textField = [[UITextField alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 260, 40), NO)];
            textField.center =  flexibleCenter(CGPointMake(300 / 2, 155));
            textField.placeholder = @"请输入密码";
            CGRect userNameFrame = [textField frame];
            userNameFrame.size.width = 15.0f;
            UIView *userNameLeftview = [[UIView alloc] initWithFrame:userNameFrame];
            textField.leftViewMode = UITextFieldViewModeAlways;
            textField.leftView = userNameLeftview;
            textField;
        });
    }
    return _passwordTF;
}

- (UITextField *)repeatPasswordTF {
    if (!_repeatPasswordTF) {
        _repeatPasswordTF = ({
            UITextField *textField = [[UITextField alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 260, 40), NO)];
            textField.center =  flexibleCenter(CGPointMake(300 / 2, 215));
            textField.placeholder = @"请再次输入密码";
            CGRect userNameFrame = [textField frame];
            userNameFrame.size.width = 15.0f;
            UIView *userNameLeftview = [[UIView alloc] initWithFrame:userNameFrame];
            textField.leftViewMode = UITextFieldViewModeAlways;
            textField.leftView = userNameLeftview;
            textField.layer.borderColor = THEMECOLORLINE.CGColor;
            textField;
        });
    }
    return _repeatPasswordTF;
}

- (UITextField *)phoneNumberTF {
    if (!_phoneNumberTF) {
        _phoneNumberTF = ({
            UITextField *textField = [[UITextField alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 260, 40), NO)];
            textField.center =  flexibleCenter(CGPointMake(300 / 2, 35));
            textField.placeholder = @"请输入手机号";
            CGRect userNameFrame = [textField frame];
            userNameFrame.size.width = 15.0f;
            UIView *userNameLeftview = [[UIView alloc] initWithFrame:userNameFrame];
            textField.leftViewMode = UITextFieldViewModeAlways;
            textField.leftView = userNameLeftview;
            textField.layer.borderColor = THEMECOLORLINE.CGColor;
            textField;
        });
    }
    return _phoneNumberTF;
}

- (UITextField *)codeTF {
    if (!_codeTF) {
        _codeTF = ({
            UITextField *textField = [[UITextField alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 130, 40), NO)];
            textField.center =  flexibleCenter(CGPointMake(300 / 4 + 12, 95));
            textField.placeholder = @"验证码";
            CGRect userNameFrame = [textField frame];
            userNameFrame.size.width = 15.0f;
            UIView *userNameLeftview = [[UIView alloc] initWithFrame:userNameFrame];
            textField.leftViewMode = UITextFieldViewModeAlways;
            textField.leftView = userNameLeftview;
            textField.layer.borderColor = THEMECOLORLINE.CGColor;
            textField;
        });
    }
    return _codeTF;
    
}
- (UIButton *)completeButton {
    if (!_completeButton) {
        _completeButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = flexibleFrame(CGRectMake(0, 0, 300, 40), NO);
            button.center =  flexibleCenter(CGPointMake(WIDTH / 2, 560));
            button.titleLabel.font = [UIFont systemFontOfSize:18];
            button.layer.borderColor = THEMECOLOR.CGColor;
            button.layer.masksToBounds = YES;
            button.layer.borderWidth = 1;
            button.layer.cornerRadius = 5.0F;
            button.backgroundColor = THEMECOLOR;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button setTitle:@"完成注册" forState:UIControlStateNormal];
            button;
        });
    }
    return _completeButton;
}

- (UIView *)textView {
    if (!_textView) {
        _textView = ({
            UIView *view = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 300, 240), NO)];
            view.center =  flexibleCenter(CGPointMake(375 / 2, 370 - 64));
            view.layer.cornerRadius = 10;
            for (int i = 0; i < 3; i ++) {
                UIView *line = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 250, 1), NO)];
                line.center =  flexibleCenter(CGPointMake(300 / 2, 60 * i +60));
                line.layer.borderWidth = 0.5;
                line.layer.borderColor = [UIColor colorWithWhite:0.811 alpha:1.000].CGColor;
                [view addSubview:line];
            }
            UIView *pins1 = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(39.5 + 4, 0, 2, 8), NO)];
            pins1.backgroundColor = [UIColor colorWithWhite:0.537 alpha:1.000];
            [view addSubview:pins1];
            UIView *pins = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(262.5 - 6, 0, 2, 8), NO)];
            pins.backgroundColor = [UIColor colorWithWhite:0.537 alpha:1.000];
            [view addSubview:pins];
            view.layer.shadowColor = [UIColor blackColor].CGColor;//阴影颜色
            view.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
            view.layer.shadowOpacity = 0.5;//不透明度
            view.layer.shadowRadius = 10.0;//半径
            view.backgroundColor = [UIColor colorWithRed:1.000 green:0.976 blue:0.721 alpha:1.000];
            view;
        });
    }
    return _textView;
}


- (AnimationView *)animationView {
    if (!_animationView) {
        _animationView = ({
            AnimationView *view = [[AnimationView alloc] init];
            view.backgroundColor = [UIColor clearColor];
            view.frame = flexibleFrame(CGRectMake(375 / 2, 0, 375.0, 375.0), NO);
            view.layer.position = flexibleCenter(CGPointMake(375.0 / 2, 0));
            view.layer.anchorPoint = CGPointMake(0.5, 0);
            
            [view.layer addAnimation:[self KeyrotationAnimation]forKey:@""];
            view;
        });
    }
    return  _animationView;
}
- (UIView *)downView {
    if (!_downView) {
        _downView = ({
            UIView *view = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(0, 64.0, 375, 500), NO)];
            view;
        });
    }
    return _downView;
}

@end
